<%= render 'base' %>
<%= content_for :breadcrumb do %>
  <li class="active">查看贴子</li>
<% end %>
<%= render 'sidebar' %>
<div class="content">
	<div class="topics box">
		<div class="topic">  
		  <div class="pull-right avatar_large">
				<%= user_avatar_tag(@topic.user) %>
			</div>  
	    <div class="infos">
				<h1><%= truncate(@topic.title, :length => 100) %></h1>
				<div class="info leader">
					由 <%= user_name_tag(@topic.user) %>
					在 <a href="<%= node_topics_path(@topic.node_id) %>"><%= @topic.node.name %></a> 节点中发起
				</div>
				<div class="info time">
					<% if @topic.last_reply_user.blank? %>
						发布于 <%= timeago(@topic.created_at) %>
					<% else %>
						最后由 <%= user_name_tag(@topic.last_reply_user) %> 回复于 <%= timeago(@topic.replied_at) %>
					<% end %>
					, <%= @topic.hits %> 次阅读
				</div>
			</div>			
		</div>
		<div class="body">
			<%= format_topic_body(@topic.body) %>
		</div>
		<div class="tools">
		  <% if owner?(@topic) %>
  			<a href="<%= edit_topic_path(@topic.id) %>">修改</a>
  			<%= link_to "删除", topic_path(@topic.id), :method => :delete, :confirm => "确定要删除么？" %>
			<% end %>
		</div>
	</div>
  <% if @replies.blank? %>
    <div class="no_result">
      暂无回复。
    </div>
  <% else %>
  <div id="replies" class="box">
    <div class="total">
      截止 <%= l @topic.replied_at, :format => :long %>, 共收到 <%= @topic.replies_count %> 条回复
    </div>
    <% @replies.each_with_index do |reply,i| %>
      <div class="reply" id="reply<%= i + 1 %>">
        <div class="pull-left face"><%= user_avatar_tag(reply.user) %></div>
        <div class="infos">
          <div class="info clearfix">
            <span class="name"><%= user_name_tag(reply.user) %></span>
            <span class="time"><%= i + 1 %>楼, 回复于 <%= timeago(reply.created_at) %>
              <% if owner?(reply) %>
          			<a href="<%= edit_reply_path(reply.id) %>">修改</a>
        			<% end %>
             </span>
          </div>
          <div class="body">
            <%= format_topic_body(reply.body) %>
          </div>
        </div>
      </div>
    <% end %>
  </div>
  <% end %>
	<% if current_user %>
  <div id="reply" class="form box">
    <h4>回复</h4>
    <%= form_for(Homeland::Reply.new,:url => reply_topic_path(params[:id])) do |f| %>
      <div class="pull-right">
        <button type="submit" class="btn primary">提交回复</button><br />
        <span class="help-inline">Ctrl+Enter</span>
      </div>
      <div class="clearfix">
        <%= f.text_area :body,:class => "span10", :rows => "4" %>
      </div>

    <% end %>
  </div>
	<% else %>
	<div id="reply" class="form box">
		<div style="padding:20px;">
		需要 <a href='/account/sign_in' class="btn primary">登录</a> 后回复方可回复, 如果你还没有账号 <a href="/account/sign_up" class="btn danger"> 点击这里注册</a>。
		</div>
	</div>
	<% end %>
</div>
